package com.zyw.codegen.java.elements;

import com.zyw.orm.support.page.Page;
import org.mybatis.generator.api.dom.java.*;
import org.mybatis.generator.codegen.mybatis3.javamapper.elements.AbstractJavaMapperMethodGenerator;

import java.util.Set;
import java.util.TreeSet;

/**
 * @author zhangyw
 * @date 2017/3/14 11:42
 */
public class FindByPageMethodGenerator extends AbstractJavaMapperMethodGenerator {

    public FindByPageMethodGenerator() {
    }

    @Override
    public void addInterfaceElements(Interface interfaze) {

        FullyQualifiedJavaType returnType = FullyQualifiedJavaType.getNewListInstance();
        FullyQualifiedJavaType recordType =
                new FullyQualifiedJavaType(introspectedTable.getBaseRecordType());
        returnType.addTypeArgument(recordType);

        FullyQualifiedJavaType paramType = new FullyQualifiedJavaType(Page.class.getName());
        paramType.addTypeArgument(recordType);

        Set<FullyQualifiedJavaType> importedTypes = new TreeSet<FullyQualifiedJavaType>();
        importedTypes.add(FullyQualifiedJavaType.getNewListInstance());
        importedTypes.add(recordType);
        importedTypes.add(new FullyQualifiedJavaType(Page.class.getName()));

        Method method = new Method();
        method.setVisibility(JavaVisibility.PUBLIC);
        method.setName("findByPage");
        method.addParameter(new Parameter(paramType, "page"));
        method.setReturnType(returnType);

        addMapperAnnotations(interfaze, method);

        context.getCommentGenerator().addGeneralMethodComment(method,
                introspectedTable);

        if (true) {
            interfaze.addImportedTypes(importedTypes);
            interfaze.addMethod(method);
        }
    }

    public void addMapperAnnotations(Interface interfaze, Method method) {

    }
}
